<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>牧心农业</title>
    <link rel="stylesheet" type="text/css" href="/static/css/eui.css" />
    <link rel="stylesheet" type="text/css" href="/static/css/mobile.css" />
    <link rel="stylesheet" type="text/css" href="/static/css/iconfont.css" />
    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/js/doT.min.js"></script>
    <script src="/static/js/swipe.js"></script>
    <script src="/static/js/func.js"></script>
</head>
<body>
    <input name="_csrf" type="hidden" id="_csrf" value="<{$app->request->csrfToken}>">
    <div class="content margin_top_foot">
        <div class="searchbar fixed_top bg_mx_green white"></div>
        <div class="refresh_content">
            <div class="pull_refresh">
                <div class="swipe">
                    <div class='swipe-wrap'></div>
                    <ul class="position"></ul>
                </div>
                <div class="font_16 margin_b_10 bg_white lineheight_4 text_center flex title_nav">
                    <{foreach $category as $key => $row}>
                    <div class="flex_1 <!--active_border-->">
                        <a href="<{url route='/articlesite/site/list' cateid=$row['id']}>"><{$row['name']}></a>
                    </div>
                    <{/foreach}>
                </div>
                <div class="bg_white lists"></div>
            </div>
            <div class="refresh_load"><div class="refresh_pull_arrow"></div></div>
        </div>
        <div class="sidebar fixed lineheight_4 white hide"></div>
        <footer class="foot_tab fixed_bottom mx_green font_16"></footer>
    </div>
    <div class="toast"></div>
    <!-- toast模版 -->
    <script type="text/template" charset="utf-8" id='toast_template'>
        <i class="iconfont icon-toast{{=it.icon}}"></i>
        <div class="toast_text">{{=it.text}}</div>
    </script>
    <script type="text/template" charset="utf-8" id='swipe_template'></script>
    <script type="text/template" charset="utf-8" id='nav_template'></script>
    <script type="text/template" charset="utf-8" id='article_template'></script>
    <script>
        // 页面初始化
            loadsearchbar(function(){
                $(".header_usercenter").show().next().hide()
            });
            var banner = <{$banner}>;
            loadswipe(banner);
            var lists = <{$article}>,evalarticle;
            loadarticle(lists)
            loadfootbar();
        // 搜索
            var evalToast = doT.template($("#toast_template").text());
            $(".content").on("input",".searchbar_input input",function(){
                var that = this;
                var keywords = $(this).val();
                if(keywords){
                    $.post("/articlesite/site/search",{keywords:keywords,_csrf:$('#_csrf').val()},function(res){
                        if(res.status && res.status == 1){
                            toast("attention",res.msg)
                        }else{
                            $(".lists").html(evalarticle(res))
                        }
                     },"json")
                }
            })
            function search(obj){
                var keywords = $(obj).next().val();
                if(keywords){
                    $.post("/articlesite/site/search",{keywords:keywords,_csrf:$('#_csrf').val()},function(res){
                        if(res.status && res.status == 1){
                            toast("attention",res.msg)
                        }else{
                            $(".lists").html(evalarticle(res))
                        }
                    },"json")
                }
            }
        // 下拉加载更多
            var pindex = 1;
            var pullRefresh = new mobileRefresh({
                container: document.querySelector('.refresh_content'),
                triggerDistance: 100,
                type:"up"
            },function(){
                $.post("/articlesite/site/load-more",{pindex:++pindex,_csrf:$('#_csrf').val()},function(res){
                    pullRefresh.cancelLoading();
                    if(res.length){
                        $(".lists").append(evalarticle(res));
                    }else{
                        toast("attention","已经到底了");
                        // $(".refresh_content").off('touchstart');
                        // $(".refresh_content").off('touchmove');
                        // $(".refresh_content").off('touchend');
                        // console.log($(".refresh_content"))
                        document.querySelector('.refresh_content').removeEventListener('touchstart',myfunc)
                        document.querySelector('.refresh_content').removeEventListener('touchmove',myfunc)
                        document.querySelector('.refresh_content').removeEventListener('touchend',myfunc)
                        function myfunc(){
                            return;
                        }
                    }
                },"json")
            })
    </script>
</body>
</html>